package leetcode.每日一题;

import org.junit.Test;

import java.util.Arrays;

/**
 * @author :songyaozhang
 * @date :Created 2021/9/10 14:46
 * @description :
 */
public class 找到需要补充粉笔的学生编号 {
  @Test
  public void test() {
    Solution solution = new Solution();
    System.out.println(solution.chalkReplacer(new int[]{3, 4, 1, 2}, 25));
  }

  class Solution {
    public int chalkReplacer(int[] chalk, int k) {
      long total = 0;
      for (int num : chalk) {
        total += num;
      }
      k %= total;
      int res = -1;
      for (int i = 0; i < chalk.length; i++) {
        if (chalk[i] > k) {
          res = i;
          break;
        }
        k -= chalk[i];
      }
      return res;
    }
  }

}
